<table id="staff_applyInfo" data-options="fit:true"></table>
<script>
$(function(){
	$('#staff_applyInfo').datagrid({
		url:'../applyInfo/Get_OneApplyInfo',
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'astatus',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'aids',title:'',width:100,align:'center',checkbox:true},
			{field:'aid',title:'申请编号',width:100,align:'center'},
			{field:'laddr',title:'维修地区',width:300,align:'center'},
			{field:'aok',title:'是否通过',width:50,align:'center',formatter: function(value,row,index){
				if (row.aok==1){
					return "已通过";
				} else {
					return "未通过";
				}
			}
			},
			{field:'astatus',title:'是否维修',width:50,align:'center',sortable:true,
				formatter: function(value,row,index){
					if (row.astatus==1){
						return "已维修";
					} else {
						return "未维修";
					}
				}	
			}
		]],
		toolbar: [{
			iconCls: 'icon-add',
			text:'添加',
			handler: function(){
				$("#add_applyInfo").dialog("open");
			}
		},'-',{
			iconCls: 'icon-edit',
			text:'已维修',
			handler: function(){
				var aids=$('#staff_applyInfo').datagrid('getSelections');
				if(aids.length==0){
					$.messager.alert('错误提示','请选择删除项!','error');
					return;
				}
				var astatus=aids[0].astatus;
				if(astatus==1){
					$.messager.alert('错误提示','请勿重复操作!','error');
					$('#staff_applyInfo').datagrid('clearSelections');
					return;
				}
				var aok=aids[0].aok;
				if(aok==0){
					$.messager.alert('错误提示','请联系管理员后操作!','error');
					$('#staff_applyInfo').datagrid('clearSelections');
					return;
				}
				if(aids.length>1){
					$.messager.alert('错误提示','事关重大,请逐项选择!','error');
					$('#staff_applyInfo').datagrid('clearSelections');
				}else{
					var aid=aids[0].aid;
					var laddr = aids[0].laddr;
					$.ajax({
					    url: "../applyInfo/updateAstatus",    //请求的url地址
					    dataType: "json",   //返回格式为json
					    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
					    type: "POST", 
					    data: { "aid": aid, "laddr":laddr},    //参数值
					    success: function(data) {
					    	if(parseInt($.trim(data.obj))>=1){
					    		$.messager.show({
									title:'成功提示',
									msg:'修改信息成功！',
									timeout:3000,
									showType:'slide'
								});
								$('#staff_applyInfo').datagrid("reload");
					    	}else{
					    		$.messager.alert('错误提示','网络错误,请稍后重试!','error');
					    	}
					    },
					});
				}
			}
		},'-',{
			iconCls: 'icon-reload',
			text:'刷新',
			handler: function(){
				$('#staff_applyInfo').datagrid("reload");
			}
		}]
	});
});

function add_applyInfo(){
	var addr=$("#addr_applyInfo").val();
	$.ajax({
	    url: "../applyInfo/Add_applyInfo",    //请求的url地址
	    dataType: "json",   //返回格式为json
	    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
	    type: "POST", 
	    data: { "laddr": addr},    //参数值
	    success: function(data) {
	    	if(parseInt($.trim(data.obj))>=1){
	    		$.messager.show({
					title:'成功提示',
					msg:'申请已经提交，请耐心等待管理员审核!',
					timeout:3000,
					showType:'slide'
				});
	    		$("#addr_applyInfo option:first").prop("selected", 'selected'); 
	    		$("#add_applyInfo").dialog("close");
				$('#staff_applyInfo').datagrid("reload");
	    	}else{
	    		$.messager.alert('错误提示','网络错误,请稍后重试!','error');
	    	}
	    },
	});
}
</script>
<div id="add_applyInfo" class="easyui-dialog" title="维修申请" style="width:400px;height:150px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<script type="text/javascript">
		$(function(){
			$.ajax({
			    url: "../locationInfo/Get_AllAddr",    //请求的url地址
			    dataType: "json",   //返回格式为json
			    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
			    type: "POST", 
			    success: function(data) {
			    	var info="";
			    	$.each(data.rows,function(index,item){
			    		info+="<option value="+item+">"+item+"</option>";
			    	});
			    	$("#addr_applyInfo").append(info);
			    },
			});
		});
	</script>
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label>维修地区：</label>
		<select style="width:200px;text-align: center;" id="addr_applyInfo">
			<option value="">请选择维修地区</option>
		</select>
		<input type="button" value="申请" style="width:80px;" onclick="add_applyInfo()"/>
	</p>
</div>
